package cn.bs.ktv.model;

import android.util.Log;

import com.blankj.utilcode.util.StringUtils;
import com.xuhao.didi.core.iocore.interfaces.ISendable;

import java.nio.charset.StandardCharsets;

public class DefaultData implements ISendable {
    private static final long serialVersionUID = 7591180708534696229L;

    private final String logName = DefaultData.class.getName();

    private String data;
    private String cmd;

    public DefaultData() {

    }

    public DefaultData(String cmd, String data) {
        setCmd(cmd);
        setData(data);
    }

    @Override
    public byte[] parse() {
        StringBuilder sb = new StringBuilder();
        sb.append(cmd).append(Constant.CMD_SPLIT_CHAR);
        if (!StringUtils.isEmpty(data)) {
            sb.append(data);
        }
        sb.append(Constant.END_CHAR);

        String str = sb.toString();
        Log.i(logName, "the send msg is:" + str);
        return str.getBytes(StandardCharsets.UTF_8);
    }

    public void setCmd(String cmd) {
        this.cmd = cmd;
    }

    public void setData(String data) {
        this.data = data;
    }
}
